package com.sg.zhui.visitor.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.sg.zhui.visitor.R;
import com.sg.zhui.visitor.bean.ApplyListBean;
import com.sg.zhui.visitor.widget.RecyclerViewAdapter;
import com.sg.zhui.visitor.widget.ViewHolderHelper;


/**
 * Created by chenlipeng on 2018/8/22 0022
 * describe:  申请记录的适配器
 */
public class ApplyForRecordAdapter extends RecyclerViewAdapter<ApplyListBean> {
    private final Boolean isVisitor;

    public ApplyForRecordAdapter(RecyclerView recyclerView, Boolean isVisitor) {
        super(recyclerView, R.layout.applyfor_record_list_item_layout);
        this.isVisitor = isVisitor;
    }

    //4、申请列表如是访客，显示车牌号，如是员工，把车牌号变为访问部门，其他不变。
    @Override
    protected void fillData(ViewHolderHelper viewHolderHelper, int position, ApplyListBean model) {

//        mView = (View) findViewById(R.id.view);
//        mTv_type = (TextView) findViewById(R.id.tv_type);
//        mTv_visitor_name = (TextView) findViewById(R.id.tv_visitor_name);
//        mWhat_kindof_data = (TextView) findViewById(R.id.what_kindof_data);
//        mTv_carnum_branch = (TextView) findViewById(R.id.tv_carnum_branch);
//        mTv_applyfor_time = (TextView) findViewById(R.id.tv_applyfor_time);
//        mTv_visitor_time = (TextView) findViewById(R.id.tv_visitor_time);

        viewHolderHelper.setText(R.id.tv_visitor_name, model.getVisitorName());
        viewHolderHelper.setText(R.id.tv_visitor_tel, model.getVisitorTel());
//        viewHolderHelper.setText(R.id.tv_apply_state, model.getApplyState());

//        授权者有值就是授权的  没值就是申请的   authorizerName
        if (TextUtils.isEmpty(model.getAuthorizerName())) {
            viewHolderHelper.setText(R.id.tv_type, "申请");
        } else {
            viewHolderHelper.setText(R.id.tv_type, "授权");
        }

        viewHolderHelper.setText(R.id.tv_by_interviewer_name, model.getIntervieweeName());//intervieweeName被访问者名字

//        可以判断值有没有  没有应该就是访客  有应该就是员工
        if (TextUtils.isEmpty(model.getDetpartmentName())) {
            viewHolderHelper.setText(R.id.what_kindof_data, "车牌号");
            viewHolderHelper.setText(R.id.tv_carnum_branch, model.getVehicleNo());//vehicleNo
        } else {
            viewHolderHelper.setText(R.id.what_kindof_data, "被访部门");
            viewHolderHelper.setText(R.id.tv_carnum_branch, model.getDetpartmentName());//detpartmentName部门名称
        }

        viewHolderHelper.setText(R.id.tv_applyfor_time, model.getCreatedDate());//申请日期
        viewHolderHelper.setText(R.id.tv_visitor_time, model.getAccessStart());//访问日期

//        valid-使用中、unvalid-待生效、over-已过期
//        申请记录与授权记录 状态现在返回这三个英文
        String status = model.getApplyState();
        TextView tv_apply_state = (TextView) viewHolderHelper.getView(R.id.tv_apply_state);

        if (status.equals("valid")) {
            tv_apply_state.setText("使用中");
        } else if (status.equals("unvalid")) {
            tv_apply_state.setText("待生效");
        } else {
            tv_apply_state.setText("已过期");
        }


    }
} /**
 * accessEnd : 2018年08月21日
 * accessStart : 2018年08月16日
 * applyState : 使用中
 * authorizerId : 8ea60114dda44e18b58f4fc067861d59
 * authorizerName : 爷本年少
 * companyId : 0
 * companyName :
 * createdDate : 2018年08月16日
 * departmentId : 0
 * detpartmentName :
 * intervieweeId : 8ea60114dda44e18b58f4fc067861d59
 * intervieweeName : 爷本年少
 * noReason :
 * sid : 6c3f4ed2d5bc4150817ff10038aa1f71
 * vehicleNo : 无
 * visitReason : U盾就觉得
 * visitorId : a2a841587b40445384cbac1d16228699
 * visitorName : 春春
 * visitorTel : 15811236556
 */
